package redis

import (
	"strconv"
	"time"
)

// 缓存短信验证码
func RedisSetSmsCode(mobile, code, sale string) {
	key := "sms:" + mobile + sale
	redisClient.Set(key, code, time.Minute*10)
}

// 获取短信验证码
func RedisGetSmsCode(mobile, sale string) string {
	key := "sms:" + mobile + sale
	return redisClient.Get(key).Val()
}

// 销毁短信验证码
func RedisdelSmsCode(mobile, sale string) {
	key := "sms:" + mobile + sale
	redisClient.Del(key)
}

//同步redis 虚拟库存，redis 的 list

func SynCGoodsStock(goodsId, goodsStock int) {
	key := "goods_id_" + strconv.Itoa(goodsId)
	for i := 0; i < goodsStock; i++ {
		redisClient.RPush(key, goodsId)
	}

}

// 获取虚拟库存
func StockGoods(goodsId int) (goodsStock int) {
	key := "goods_id_" + strconv.Itoa(goodsId)
	return int(redisClient.LLen(key).Val())
}
